<template>
  <div>
    <el-menu :default-active="path"
             background-color="#545c64"
             text-color="#fff"
             active-text-color="#409EFF"
             class="el-menu-vertical-demo"
             style="width: 190px;min-height: calc(100vh - 50px);
             overflow: hidden;"
             router>
      <el-submenu index="1">
        <template #title>
          <i class="el-icon-setting"></i>
          <span>系统管理</span>
        </template>
        <el-menu-item index="/books">书籍管理</el-menu-item>
        <el-menu-item index="/news">新闻管理</el-menu-item>
        <el-menu-item index="/users" v-if="user.role==='1'">用户管理</el-menu-item>
      </el-submenu>
    </el-menu>
  </div>
</template>

<script>
import request from "@/utils/request";

export default {
  name: "Aside",
  data() {
    return {
      user: {},
      path: this.$route.path //设置高亮
    }
  },
  created() {
    // 读取sessionStorage
    let userJson = sessionStorage.getItem("user")
    if (userJson) {
      this.user = JSON.parse(userJson)
      // console.log(this.user)
    }
    // 请求验证
    request.get('/users/' + this.user.id).then(res => {
      console.log(res)
      if (res.codes === "200") {
        this.user = res.data
      }
    })
  }
}
</script>

<style>
</style>
